package com.sgcc.activiti.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.activiti.domain.OIndexMaintain;
import com.sgcc.activiti.service.IOIndexMaintainService;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.page.TableDataInfo;

/**
 * 指标维护Controller
 * 
 * @author sgcc
 * @date 2021-04-09
 */
@RestController
@RequestMapping("/OIndexMaintain")
public class OIndexMaintainController extends BaseController
{
    @Autowired
    private IOIndexMaintainService oIndexMaintainService;

    /**
     * 查询指标维护列表
     */
    //@PreAuthorize(hasPermi = "activiti:OIndexMaintain:list")
    @GetMapping("/list")
    public TableDataInfo list(OIndexMaintain oIndexMaintain)
    {
        startPage();
        List<OIndexMaintain> list = oIndexMaintainService.selectOIndexMaintainList(oIndexMaintain);
        return getDataTable(list);
    }

    /**
     * 导出指标维护列表
     */
    //@PreAuthorize(hasPermi = "activiti:OIndexMaintain:export")
    @Log(title = "指标维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OIndexMaintain oIndexMaintain) throws IOException
    {
        List<OIndexMaintain> list = oIndexMaintainService.selectOIndexMaintainList(oIndexMaintain);
        ExcelUtil<OIndexMaintain> util = new ExcelUtil<OIndexMaintain>(OIndexMaintain.class);
        util.exportExcel(response, list, "OIndexMaintain");
    }

    /**
     * 获取指标维护详细信息
     */
    //@PreAuthorize(hasPermi = "activiti:OIndexMaintain:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(oIndexMaintainService.selectOIndexMaintainById(id));
    }

    /**
     * 新增指标维护
     */
    //@PreAuthorize(hasPermi = "activiti:OIndexMaintain:add")
    @Log(title = "指标维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OIndexMaintain oIndexMaintain)
    {
        return toAjax(oIndexMaintainService.insertOIndexMaintain(oIndexMaintain));
    }

    /**
     * 修改指标维护
     */
    //@PreAuthorize(hasPermi = "activiti:OIndexMaintain:edit")
    @Log(title = "指标维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OIndexMaintain oIndexMaintain)
    {
        int i = oIndexMaintainService.updateOIndexMaintain(oIndexMaintain);
        if (i > 0){
            return AjaxResult.success("修改成功！", 200);
        }else {
            return AjaxResult.error("指标权重总和不能超过100%！", 201);
        }
    }

    /**
     * 删除指标维护
     */
    //@PreAuthorize(hasPermi = "activiti:OIndexMaintain:remove")
    @Log(title = "指标维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oIndexMaintainService.deleteOIndexMaintainByIds(ids));
    }
}
